/**
 * 
 */
package fr.gfi.agraf.vue.action.visualiser;

import java.util.List;

import org.apache.log4j.Logger;

import fr.gfi.agraf.exception.AgrafException;
import fr.gfi.agraf.service.IPerimetreService;
import fr.gfi.agraf.utils.PropertiesUtils;
import fr.gfi.agraf.utils.SpringFactory;
import fr.gfi.agraf.vue.action.AbstractApplicationSupportAction;
import fr.gfi.agraf.vue.action.visualiser.perimetre.VisualiserPerimetreAction;
import fr.gfi.agraf.vue.bean.PerimetreDTO;

/**
 * @author Zakaria Classe abstraite qui récupere la liste des perimetres
 */
public abstract class AbstractGetPerimetreAction extends AbstractApplicationSupportAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 5585833786229654756L;

	private static final String PERIMETRE_SERVICE = "PerimetreService";

	private List<PerimetreDTO> perimetreList;

	private List<String> listeInfoPage;

	/**
	 * Logger
	 */
	private final static Logger LOGGER = Logger.getLogger(VisualiserPerimetreAction.class);

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * fr.gfi.agraf.vue.action.AbstractApplicationSupportAction#executeAction()
	 */
	@Override
	public String executeAction() throws Exception {
		// Spring, recupere le service perimetre
		final IPerimetreService perimetreService = (IPerimetreService) SpringFactory.getApplicationContext()
				.getBean(PERIMETRE_SERVICE);

		try {
			// fait appel au service perimetre
			setPerimetreList(perimetreService.getListePerimetre());
		} catch (final AgrafException ae) {
			// Recupére le message
			final String message = PropertiesUtils.getProperty(ae.getKey());
			// Ajoute action message
			addActionMessage(message);
			LOGGER.error(message, ae);
			return ERROR;
		}
		setMessageInfo();
		return SUCCESS;
	}

	/**
	 * Permet de setter les messages dans
	 */
	public abstract void setMessageInfo();

	/**
	 * @return the perimetreList
	 */
	public List<PerimetreDTO> getPerimetreList() {
		return perimetreList;
	}

	/**
	 * @param perimetreList
	 *            the perimetreList to set
	 */
	public void setPerimetreList(final List<PerimetreDTO> perimetreList) {
		this.perimetreList = perimetreList;
	}

	/**
	 * @return the listeInfoPage
	 */
	public List<String> getListeInfoPage() {
		return listeInfoPage;
	}

	/**
	 * @param listeInfoPage
	 *            the listeInfoPage to set
	 */
	public void setListeInfoPage(final List<String> listeInfoPage) {
		this.listeInfoPage = listeInfoPage;
	}
}
